1 00:00:00,760 --> 00:00:05,800 Okay, so we are almost finished with the lobby, and the last thing we need to do here is to further 2 00:00:05,800 --> 00:00:07,750 improve the lobbies ambience. 3 00:00:07,750 --> 00:00:13,810 We can do this by flickering the lights inside of our game and making our Squidward friend here disappear. 4 00:00:13,810 --> 00:00:19,060 And then we can go ahead and replace him with our handsome Squidward monster that will go randomly somewhere 5 00:00:19,060 --> 00:00:19,930 on this map. 6 00:00:19,930 --> 00:00:23,380 So over here we have some of the models for our handsome Squidward. 7 00:00:23,380 --> 00:00:27,880 So when the lights go out and the building becomes dark, we can place this guy somewhere on the map. 8 00:00:27,880 --> 00:00:32,590 So that way when the person sitting there in the lobby, they will see this creepy dude staring at them, 9 00:00:32,800 --> 00:00:35,110 so it'll add a nice ambience effect. 10 00:00:35,110 --> 00:00:38,440 Now I have these invisible parts placed all over the workspace. 11 00:00:38,440 --> 00:00:41,290 You'll see one right here in this position where Squidward is at. 12 00:00:41,290 --> 00:00:43,810 I believe I have another one right here in the kitchen. 13 00:00:43,810 --> 00:00:46,300 There are some up here, like there's one up here. 14 00:00:46,300 --> 00:00:48,610 I believe I have one over here somewhere. 15 00:00:48,610 --> 00:00:49,570 There's one. 16 00:00:49,570 --> 00:00:51,580 And I believe there's another one back here. 17 00:00:51,580 --> 00:00:52,090 Yep. 18 00:00:52,210 --> 00:00:53,500 And all these different parts. 19 00:00:53,500 --> 00:00:58,990 We're going to use the keyframe on them to position our handsome Squidward randomly on the map. 20 00:00:58,990 --> 00:01:03,250 So as you can see, we have six different positions that we can go ahead and place them, and when the 21 00:01:03,250 --> 00:01:07,570 lights go out, we're going to put them at one of these random positions just so it looks nice. 22 00:01:07,570 --> 00:01:10,360 And our lobby has a bit of ambience to it. 23 00:01:10,360 --> 00:01:15,640 So to get started, we can go ahead and go into the server and script the last module script we need 24 00:01:15,640 --> 00:01:17,950 to complete, which is going to be our Squidward service. 25 00:01:17,950 --> 00:01:21,070 And this is going to handle all of the animations for this. 26 00:01:21,070 --> 00:01:25,870 Squidward and that Squidward, and flickering the lights and moving the squidwards around so we can 27 00:01:25,870 --> 00:01:27,580 go ahead and open this bad boy up. 28 00:01:27,580 --> 00:01:31,900 And the only two surfaces we're going to need in here is replicated storage. 29 00:01:34,740 --> 00:01:37,500 And then we're also going to need the sound service. 30 00:01:41,270 --> 00:01:44,030 Then we can create the table that will represent the service. 31 00:01:44,030 --> 00:01:45,140 So squid. 32 00:01:46,890 --> 00:01:52,050 Word service, and then we can go ahead and return that service at the very end here. 33 00:01:52,050 --> 00:01:55,590 And we're only going to need one function to start the service. 34 00:01:55,590 --> 00:01:58,290 We're not going to have to initialize anything in the service. 35 00:01:58,290 --> 00:02:03,720 So we can just do function inside of our Squidward service and we'll call it start. 36 00:02:03,720 --> 00:02:06,180 And we'll go ahead and fill this out later. 37 00:02:06,740 --> 00:02:10,370 Now, some of the variables we're going to need in here is quite a few. 38 00:02:10,400 --> 00:02:15,140 The first thing we need to make a reference to is that play sound event in replicated storage. 39 00:02:15,140 --> 00:02:19,730 So replicated storage, dot events, dot remotes and get the play sound event. 40 00:02:19,730 --> 00:02:22,910 That way we can tell the player to play sounds on their end. 41 00:02:23,180 --> 00:02:28,370 And then we're also going to get all of the different flickering sounds that we have within our ambience 42 00:02:28,370 --> 00:02:28,700 folder. 43 00:02:28,700 --> 00:02:34,190 So there's a light flicker folder here, and there are two flicker sounds that we have that we're going 44 00:02:34,190 --> 00:02:36,620 to play when we flicker the lights on and off. 45 00:02:36,620 --> 00:02:39,800 So we can go ahead and call this flicker sounds. 46 00:02:40,800 --> 00:02:47,220 Equal the sound service dot ambience dot light flicker and we'll get all the children. 47 00:02:47,780 --> 00:02:53,210 And then we're also going to get all of the different random positions that we have for our handsome 48 00:02:53,210 --> 00:02:53,810 Squidward. 49 00:02:53,810 --> 00:02:57,140 So what we need to do is create a variable. 50 00:02:57,140 --> 00:03:04,070 I'll call it random positions is equal to workspace, and it's inside of the characters folder. 51 00:03:04,070 --> 00:03:06,320 So dot characters. 52 00:03:07,330 --> 00:03:11,860 And then get positions, and then we'll go ahead and get all of those different positions. 53 00:03:12,460 --> 00:03:15,370 And then I also have a default position inside of here. 54 00:03:15,370 --> 00:03:20,590 If I go to it, and this is going to be where we're going to place our handsome Squidward when he's 55 00:03:20,590 --> 00:03:21,820 not being moved around the map. 56 00:03:21,820 --> 00:03:26,200 So he'll be outside of the player's view and he'll just be chilling here before we start moving him. 57 00:03:26,200 --> 00:03:28,330 So that's going to be our default position. 58 00:03:28,600 --> 00:03:35,050 So default position is equal to workspace dot characters dot default position. 59 00:03:35,560 --> 00:03:39,010 Next up we need to make a reference to our regular Squidward who's at the counter. 60 00:03:39,010 --> 00:03:46,000 So Reg, Squidward is equal to workspace dot characters and he's called Regular Squidward. 61 00:03:46,540 --> 00:03:51,220 And then we're going to also get the humanoid and animator for this regular Squidward so we can animate 62 00:03:51,220 --> 00:03:51,580 him. 63 00:03:51,580 --> 00:03:59,380 So I'll just call this humanoid R standing for regular equal to regular Squidward dot humanoid. 64 00:03:59,380 --> 00:04:01,750 And then we'll also get his animator. 65 00:04:01,750 --> 00:04:05,590 So humanoid R dot animator. 66 00:04:05,590 --> 00:04:10,630 And then we're also going to make some references to the idalene animation that is inside of our regular 67 00:04:10,630 --> 00:04:11,140 Squidward. 68 00:04:11,140 --> 00:04:16,360 So if you remember, when we set up our regular Squidward, we have our default idle animation and then 69 00:04:16,360 --> 00:04:20,380 a bunch of other random idalene animations that we can play, and you should have updated those with 70 00:04:20,380 --> 00:04:23,320 the different IDs that you uploaded from our anim saves. 71 00:04:23,320 --> 00:04:28,480 But if you haven't done that yet, go ahead and save these animations to your Roblox account and then 72 00:04:28,480 --> 00:04:32,470 take those IDs and put them into their respective animation instances. 73 00:04:32,470 --> 00:04:38,950 But once we've done that, I'll make a reference to the idle animation for our regular Squidward, and 74 00:04:38,950 --> 00:04:42,970 that's going to be in regular Squidward Dot idle Anim one. 75 00:04:42,970 --> 00:04:47,410 And then we're also going to get all of the different idle animes that is inside of that folder. 76 00:04:47,410 --> 00:04:48,820 So regular Squidward. 77 00:04:49,700 --> 00:04:54,410 Not idle animes, and we can go ahead and get all of those different ones. 78 00:04:54,410 --> 00:05:00,590 And then I'm going to go ahead and load that basic, uh, idle animation and get a track from it. 79 00:05:00,590 --> 00:05:04,370 So we're going to call it Idle Anim Track. 80 00:05:04,370 --> 00:05:06,620 And this is going to be again for regular Squidward. 81 00:05:06,620 --> 00:05:12,200 So we're going to use the animator on him and load the animation of Idle Anim regular. 82 00:05:12,860 --> 00:05:16,970 Okay, so this section is for regular Squidward. 83 00:05:17,890 --> 00:05:23,140 And now let's create some variables and references to our handsome Squidward. 84 00:05:24,960 --> 00:05:26,730 So handsome. 85 00:05:26,790 --> 00:05:29,310 Squidward is in workspace. 86 00:05:29,520 --> 00:05:30,930 Characters. 87 00:05:30,930 --> 00:05:31,380 Dot. 88 00:05:31,410 --> 00:05:31,920 Handsome. 89 00:05:31,920 --> 00:05:32,670 Squidward. 90 00:05:33,560 --> 00:05:38,210 We're going to get his humanoid, and we'll just prefix it with H to stand for handsome. 91 00:05:38,210 --> 00:05:39,230 So handsome. 92 00:05:39,230 --> 00:05:40,100 Squidward. 93 00:05:41,030 --> 00:05:45,530 Dot humanoid and then get his animator as well. 94 00:05:49,630 --> 00:05:52,660 And then we can go ahead and make a reference to his idle animation. 95 00:05:52,660 --> 00:05:55,540 So idle anim handsome is equal to handsome. 96 00:05:55,540 --> 00:05:57,760 Squidward dot idle anim one. 97 00:05:58,320 --> 00:06:00,870 And then we'll load that animation on him as well. 98 00:06:00,870 --> 00:06:03,390 So idle and Amtrak for handsome. 99 00:06:03,870 --> 00:06:06,780 Handsome is equal to animator H. 100 00:06:07,620 --> 00:06:12,360 And we're going to load this idol and handsome onto him. 101 00:06:12,360 --> 00:06:16,170 And then last but not least, I'm going to create a new random data type. 102 00:06:18,540 --> 00:06:21,420 Okay, now we're going to need a few private functions. 103 00:06:21,420 --> 00:06:26,280 One function we'll need to change the lights in our game, or basically turn them on and turn them off. 104 00:06:26,280 --> 00:06:29,040 So we can call this toggle lights. 105 00:06:30,090 --> 00:06:34,110 And it'll get passed a boolean of whether or not we want to set them on or set them off. 106 00:06:34,110 --> 00:06:35,940 So we can just call it set on. 107 00:06:35,940 --> 00:06:37,500 And this will be a boolean. 108 00:06:37,890 --> 00:06:44,340 We'll need a function to change the visibility of our different Squidward friends, or in this case, 109 00:06:44,340 --> 00:06:51,120 we're going to be changing the, uh, visibility of our regular Squidward so we can call this function 110 00:06:51,120 --> 00:07:00,210 set Reg Squidward visibility, and we can set this to a boolean of either true or false if we want them 111 00:07:00,210 --> 00:07:02,040 to be visible or not visible. 112 00:07:03,140 --> 00:07:12,230 And then we're going to need a function to get a random, uh, animation from our where is it from our, 113 00:07:12,230 --> 00:07:14,210 uh, idle animations here. 114 00:07:14,960 --> 00:07:21,230 So we can go ahead and call this function get random track standing for animation track. 115 00:07:22,010 --> 00:07:28,280 So actually what we need to do here is we also need to load all of the different idle animations for 116 00:07:28,280 --> 00:07:29,750 our regular Squidward. 117 00:07:29,750 --> 00:07:34,460 So what we can do is we can loop through every single animation in idle animes. 118 00:07:35,620 --> 00:07:39,640 And what we're going to do is we're going to load those animations and we can store them inside of a 119 00:07:39,640 --> 00:07:43,990 table, and we can call it idle anim tracks. 120 00:07:43,990 --> 00:07:45,940 So we put this table here. 121 00:07:45,940 --> 00:07:51,280 And what we can do is we can insert into the table the different idle animation tracks. 122 00:07:51,280 --> 00:07:58,570 So what we could do is we could get this animation and use our animator on our regular Squidward and 123 00:07:58,570 --> 00:08:00,970 load this particular animation. 124 00:08:01,270 --> 00:08:06,910 And this will return back to us an animation track, so we can call it track, and then we can insert 125 00:08:06,910 --> 00:08:11,290 this track into our Idle Anim Tracks table. 126 00:08:13,290 --> 00:08:14,070 All right. 127 00:08:14,340 --> 00:08:16,830 And then with this function, this should be pretty easy. 128 00:08:16,830 --> 00:08:24,510 All we can do is we can just return one of these random tracks so we can do idle anim tracks. 129 00:08:27,670 --> 00:08:31,510 And we're going to use our RNG to get a random one. 130 00:08:31,510 --> 00:08:38,530 So we'll use next integer from starting the index at one to the max number of idle anim tracks. 131 00:08:39,010 --> 00:08:41,650 And it's just going to give us a random animation track. 132 00:08:41,650 --> 00:08:46,180 So we can actually denote that here with animation track. 133 00:08:47,160 --> 00:08:49,560 So that's what our good old function returns here. 134 00:08:50,040 --> 00:08:56,100 So inside of our start function, what we need to do is we need to have, um two loops. 135 00:08:56,100 --> 00:09:01,620 One loop is going to constantly play the animation on a regular Squidward, and it's going to wait for 136 00:09:01,620 --> 00:09:03,120 when that idle animation ends. 137 00:09:03,120 --> 00:09:08,970 And when it ends, it'll have a random chance to play one of the other different idle animation tracks 138 00:09:08,970 --> 00:09:11,310 that we have stored inside of the table here. 139 00:09:11,310 --> 00:09:15,450 And then we're going to need another loop that's going to constantly loop forever. 140 00:09:15,450 --> 00:09:20,220 And if some random number is reached, then what we could do is we could flicker the lights and make 141 00:09:20,220 --> 00:09:22,950 our Squidward disappear and have that ambience effect. 142 00:09:22,950 --> 00:09:27,390 So that means we're going to have to spawn them in two separate threads, and we can use task Dot defer 143 00:09:27,390 --> 00:09:30,390 to do this because we don't need it to run instantaneously. 144 00:09:30,390 --> 00:09:34,470 So we could do task dot, defer and spawn a new function. 145 00:09:35,290 --> 00:09:41,110 And this will have a while loop that will run forever and it'll pick out random different animation 146 00:09:41,110 --> 00:09:41,860 tracks. 147 00:09:41,860 --> 00:09:47,380 So what I'm going to do down here is I'm going to get our idle anim track on our handsome Squidward, 148 00:09:47,470 --> 00:09:49,120 and we're going to play that. 149 00:09:49,330 --> 00:09:54,100 And then what we're going to do up here is inside of our while loop. 150 00:09:54,100 --> 00:09:59,200 We're going to check if the idle anim track. 151 00:10:00,020 --> 00:10:04,190 Idle and Amtrak on our regular Squidward is plain. 152 00:10:04,190 --> 00:10:09,590 So if it's plain or if it's not plain, I mean, then we need to play it so. 153 00:10:09,620 --> 00:10:12,350 Idle and Amtrak regular play. 154 00:10:12,800 --> 00:10:17,630 And then what we're going to do with this idle animation track is we're going to wait for it to complete. 155 00:10:17,630 --> 00:10:24,110 Or basically we had that, uh, event inside of our idle animation, if you remember, it was called 156 00:10:24,110 --> 00:10:24,680 ended. 157 00:10:24,680 --> 00:10:30,440 So we need to wait for that marker to get reached so we can pass our idle anim track regular and use 158 00:10:30,440 --> 00:10:32,780 the function get marker reach signal. 159 00:10:32,780 --> 00:10:34,550 And the name was ended. 160 00:10:34,820 --> 00:10:38,420 So when this marker is reached then we'll stop yielding. 161 00:10:38,930 --> 00:10:44,630 And once we stop yielding, what we're going to do is we're going to use our RNG function and have the 162 00:10:44,630 --> 00:10:48,380 chance of something like 1 to 8 is equal to one. 163 00:10:48,590 --> 00:10:50,870 Then what we could do is we could get a random track. 164 00:10:50,870 --> 00:10:54,470 So local track is equal to get random track. 165 00:10:54,770 --> 00:10:56,900 And then we're going to play this track. 166 00:10:57,810 --> 00:11:00,570 And then we're just going to wait for this track to end. 167 00:11:01,920 --> 00:11:03,990 Because these are the tracks that do not loop. 168 00:11:03,990 --> 00:11:07,140 But our idle animation track regular does loop. 169 00:11:07,140 --> 00:11:12,570 Okay, so we'll have both the idle animation on our regular Squidward plane, and then we'll have the 170 00:11:12,570 --> 00:11:15,090 idle animation on our handsome Squidward plane. 171 00:11:15,090 --> 00:11:19,890 And what we need to do down here is create another loop using task Dot defer. 172 00:11:19,890 --> 00:11:21,180 We'll spawn a new function. 173 00:11:21,180 --> 00:11:23,160 So while true, do. 174 00:11:23,160 --> 00:11:28,470 And what we're going to do is we're going to have a random chance if RNG next integer we could do something 175 00:11:28,470 --> 00:11:30,000 like 1 to 15. 176 00:11:30,060 --> 00:11:36,300 If this is equal to one then we can go ahead and flicker the lights and change the visibility for our 177 00:11:36,300 --> 00:11:38,700 Squidward and stuff like that. 178 00:11:39,000 --> 00:11:42,240 So what we could do here is we could access our play sound event. 179 00:11:43,220 --> 00:11:48,200 And we could fire to all of the clients in the game to play a particular flickering sound. 180 00:11:48,230 --> 00:11:52,070 You could also play this flickering sound on the server as well. 181 00:11:52,070 --> 00:11:58,160 You don't have to use this event, but we're going to be using this particular module in the next section 182 00:11:58,160 --> 00:11:58,700 of our game. 183 00:11:58,700 --> 00:12:03,140 So it's kind of good to get used to how to use it now, but you can go ahead and do it anyway. 184 00:12:03,140 --> 00:12:07,820 You can either just play the different flicker sounds directly from the server, or you can fire to 185 00:12:07,820 --> 00:12:11,480 all the clients to tell them to play a particular sound on their end. 186 00:12:11,510 --> 00:12:12,560 It doesn't really matter. 187 00:12:12,560 --> 00:12:17,120 We're just doing this for practice sake so we can pick a random flickering sound. 188 00:12:17,120 --> 00:12:22,130 So inside of flicker sounds, or actually we can go ahead and make a dedicated function for this as 189 00:12:22,130 --> 00:12:22,370 well. 190 00:12:22,370 --> 00:12:22,880 Why not. 191 00:12:22,880 --> 00:12:27,320 So we can have this function be called get random flicker sound. 192 00:12:28,880 --> 00:12:32,300 And what we'll do is we'll just return Flickr sounds. 193 00:12:32,300 --> 00:12:39,830 We'll pass RNG next integer from one to the max number of Flickr sounds, and we'll get that back from 194 00:12:39,830 --> 00:12:41,720 here, which will be a sound instance. 195 00:12:41,720 --> 00:12:43,070 So this is a sound. 196 00:12:43,960 --> 00:12:48,580 So we'll get our random flicker sound and we'll just send that to the different players. 197 00:12:48,580 --> 00:12:51,220 So get random flicker sound. 198 00:12:51,770 --> 00:12:56,780 And then once we tell them to play the flicker sound, that we can go ahead and change the lights or 199 00:12:56,780 --> 00:12:58,160 toggle the lights in our game. 200 00:12:58,160 --> 00:13:02,360 So toggle lights and we want them to be off. 201 00:13:02,360 --> 00:13:05,030 So we could pass a boolean like false to this function. 202 00:13:05,030 --> 00:13:07,040 And then we can actually go ahead and fill this out. 203 00:13:07,130 --> 00:13:09,110 So we want our lights to be off. 204 00:13:09,110 --> 00:13:12,950 So if set on is true then we'll turn on the lights. 205 00:13:12,950 --> 00:13:15,170 Otherwise we'll turn off the lights. 206 00:13:15,170 --> 00:13:19,400 And since in this case we want to turn off the lights, what we'll do is we'll loop through every single 207 00:13:19,400 --> 00:13:25,370 light and ipairs workspace dot Krusty Krab, and there's a folder in there called lights that store 208 00:13:25,370 --> 00:13:26,810 all the lights in our game. 209 00:13:26,960 --> 00:13:33,110 And we can get every single descendant in there, because what we want to do is we want to check if 210 00:13:33,110 --> 00:13:35,540 this descendant is a light instance. 211 00:13:35,540 --> 00:13:39,290 So if light is a light instance. 212 00:13:40,050 --> 00:13:43,800 Then what we need to do is we need to disable the slice. 213 00:13:43,800 --> 00:13:47,130 So light dot enabled is equal to false. 214 00:13:47,130 --> 00:13:53,520 Then the next thing we need to check is to see if this instance is a part that is neon. 215 00:13:53,520 --> 00:13:57,390 So all of these different lights have this neon parts in them. 216 00:13:57,390 --> 00:14:01,290 And we want to change the color of this neon part so it's not glowing anymore. 217 00:14:01,290 --> 00:14:06,360 So what we could do is we could check if light is a base part. 218 00:14:07,420 --> 00:14:13,870 And we want to check if the light material is equal to the enum dot material of neon. 219 00:14:14,780 --> 00:14:18,740 And if it is, then what we could do is we could set an attribute on this light. 220 00:14:19,380 --> 00:14:23,340 And we're going to call it original color, because we want to store what the original color of this 221 00:14:23,340 --> 00:14:26,190 light was, and we'll just pass light color. 222 00:14:26,770 --> 00:14:30,370 And then we're going to set light color to be basically black. 223 00:14:30,370 --> 00:14:32,770 So we could actually create a constant for this. 224 00:14:33,980 --> 00:14:40,100 We'll call it black and it will be equal to a new color three of 000. 225 00:14:40,100 --> 00:14:41,360 So this is completely black. 226 00:14:41,360 --> 00:14:43,940 And we'll just set the color of the light to this color. 227 00:14:44,480 --> 00:14:48,650 Now if you want to turn on the lights then what we could do is we could basically just loop through 228 00:14:48,650 --> 00:14:49,760 every single light again. 229 00:14:49,760 --> 00:14:53,810 But this time if it is a light, then we want to enable the light. 230 00:14:54,400 --> 00:15:00,370 And instead of setting the color to black, we want to set the light's color back to its original attributes. 231 00:15:00,370 --> 00:15:04,600 So light dot color is going to be equal to light. 232 00:15:04,600 --> 00:15:06,790 Get attribute original color. 233 00:15:06,790 --> 00:15:09,670 So get attribute original color. 234 00:15:10,810 --> 00:15:13,150 And that's all we need to do for this function. 235 00:15:13,180 --> 00:15:17,320 So now when we call it here, the lights are going to be turned off. 236 00:15:17,320 --> 00:15:21,910 And then once the lights get turned off, we want to make our regular Squidward disappear so we could 237 00:15:21,910 --> 00:15:27,520 call our set regular Squidward visibility to false. 238 00:15:27,520 --> 00:15:28,930 So we'll set it to false. 239 00:15:28,930 --> 00:15:32,710 And that means we're going to have to fill out this function as well. 240 00:15:32,710 --> 00:15:38,830 So inside of this function, what we could actually do is we could access our regular Squidward, get 241 00:15:38,830 --> 00:15:45,550 his body, which is called Squidward Reg, and set the transparency of this equal to a number based 242 00:15:45,550 --> 00:15:46,600 on this boolean. 243 00:15:46,600 --> 00:15:51,550 And you might be thinking, oh yeah, we could do that with if statements, but actually we could also 244 00:15:51,550 --> 00:15:56,770 use the and and the or keywords as a ternary operator. 245 00:15:56,770 --> 00:15:58,600 Now what is a ternary operator? 246 00:15:58,600 --> 00:16:04,060 Well, a ternary operator is a special kind of operator that exists in some programming languages that 247 00:16:04,060 --> 00:16:08,110 allow you to get a value based on if a condition is true or false. 248 00:16:08,110 --> 00:16:12,610 So, for example, if a condition was true, you could get a number like five, otherwise you could 249 00:16:12,610 --> 00:16:14,170 get zero, something like that. 250 00:16:14,170 --> 00:16:19,990 Now Lua doesn't have a dedicated ternary operator, but we can actually imitate a ternary operator using 251 00:16:19,990 --> 00:16:21,790 the and and or keywords. 252 00:16:21,940 --> 00:16:28,660 So if I go down to our command line down here and I print out a boolean in the console, like true, 253 00:16:28,900 --> 00:16:30,550 you're going to be like, yep, it prints true. 254 00:16:30,550 --> 00:16:31,210 Whatever. 255 00:16:31,210 --> 00:16:36,430 Now if I print true and seven, what do you think is going to get printed out? 256 00:16:36,430 --> 00:16:38,290 Do you think true is going to get printed out? 257 00:16:38,290 --> 00:16:45,070 Well, if I hit enter, as you can see, seven gets printed out because when we're using the and keyword, 258 00:16:45,070 --> 00:16:51,010 what is happening is that each value is being checked for whether or not they're falsy or truthy. 259 00:16:51,010 --> 00:16:57,040 So since true is truthy and moved to the next condition, and since seven is truthy, it would move 260 00:16:57,040 --> 00:16:58,090 to the next condition. 261 00:16:58,090 --> 00:17:03,700 But since this is the last condition, this is the value that gets returned at the end of this little 262 00:17:03,700 --> 00:17:07,090 section here, which is why seven got printed into the console. 263 00:17:07,090 --> 00:17:10,420 So that means I can keep adding something else like five. 264 00:17:10,420 --> 00:17:11,410 So if I print it out. 265 00:17:11,410 --> 00:17:11,830 True. 266 00:17:11,830 --> 00:17:18,280 And seven and five, since five is going to be our last value checked, and since all the other previous 267 00:17:18,280 --> 00:17:21,940 values were truthy, five would get printed into the console. 268 00:17:22,520 --> 00:17:29,240 Now, if I made this false here in the middle, what's going to happen instead is that it's not going 269 00:17:29,240 --> 00:17:34,370 to print true or phi, but instead it's going to print false because that's the value that made this 270 00:17:34,370 --> 00:17:35,330 condition here. 271 00:17:35,330 --> 00:17:35,690 False. 272 00:17:35,930 --> 00:17:38,060 So if I hit enter there we go. 273 00:17:38,060 --> 00:17:40,070 We get false into the console. 274 00:17:40,660 --> 00:17:46,120 Now, this is very powerful because we can create very concise statements that act like a ternary operator. 275 00:17:46,420 --> 00:17:53,080 So let's say I had some kind of condition here, and based on this condition, I wanted to get either, 276 00:17:53,080 --> 00:17:54,850 uh, a number one or a number zero. 277 00:17:54,850 --> 00:18:02,230 So what I could do is I could have this condition and then use the and keyword and pass one or pass 278 00:18:02,230 --> 00:18:02,920 zero. 279 00:18:02,920 --> 00:18:07,450 So if condition is true, it'll pass one. 280 00:18:07,450 --> 00:18:13,810 Otherwise if condition is false it'll skip one and pass zero instead thanks to the Or keyword. 281 00:18:13,810 --> 00:18:18,160 So if I pass true here, we're going to get one printed into the console. 282 00:18:18,160 --> 00:18:18,970 There we go. 283 00:18:18,970 --> 00:18:25,150 But if I pass false here we're going to get zero printed into the console just like that. 284 00:18:25,270 --> 00:18:29,290 So that means we can use this boolean to create a very concise statement. 285 00:18:29,290 --> 00:18:36,970 So what I could do is I could set the transparency of our squid word equal to bool and 0 or 1. 286 00:18:37,890 --> 00:18:42,750 So what this is going to do is if bool is true, if we want to set the visibility of our Squidward to 287 00:18:42,750 --> 00:18:47,220 true, then it's going to set the transparency to be zero or opaque. 288 00:18:47,250 --> 00:18:53,430 Otherwise, if bool is false, it's going to skip zero, and it's going to set it to be one instead 289 00:18:53,430 --> 00:18:54,750 or fully transparent. 290 00:18:54,780 --> 00:18:55,830 Pretty cool. 291 00:18:55,830 --> 00:19:01,650 And we need to do the exact same thing for the hat of our Squidward as well. 292 00:19:01,650 --> 00:19:08,460 So we could do regular Squidward dot hat dot transparency equal to bool and 0 or 1. 293 00:19:09,140 --> 00:19:16,670 So now when we go back, once we have flickered the lights and then turned them off and then made our 294 00:19:16,670 --> 00:19:22,190 regular Squidward disappear, then we're going to wait for a random amount of time so we could do task 295 00:19:22,190 --> 00:19:29,510 dot wait and do RNG next number and wait anywhere from one to something like 1.7 seconds. 296 00:19:30,110 --> 00:19:35,240 And then what we're going to do again is we're going to flicker the lights, but turn them back on. 297 00:19:35,570 --> 00:19:39,470 So we'll get a random flicker sound and we'll set the lights to be on. 298 00:19:40,500 --> 00:19:44,100 And then we'll wait again on the next number. 299 00:19:44,770 --> 00:19:51,130 We could weight something like 0.6 to 1.5 seconds, and then this time we're going to turn the lights 300 00:19:51,130 --> 00:19:52,450 back off again. 301 00:19:53,300 --> 00:19:55,220 So false. 302 00:19:56,170 --> 00:20:00,910 And then we're going to set our handsome Squidward to be somewhere randomly on the map so we could do 303 00:20:00,940 --> 00:20:09,790 handsome Squidward humanoid route part dot C frame and set it equal to a random position so we get random 304 00:20:09,790 --> 00:20:11,500 positions and pass RNG. 305 00:20:13,380 --> 00:20:21,390 Next integer one to the max number of random positions, and we can get the key frame from that particular 306 00:20:21,390 --> 00:20:21,990 part. 307 00:20:22,320 --> 00:20:25,110 Now again, we could also put this into a function if you'd like. 308 00:20:25,110 --> 00:20:28,290 So this main while loop down here looks very clean. 309 00:20:28,290 --> 00:20:31,770 So what we could do is we could actually make one more private function. 310 00:20:31,770 --> 00:20:35,490 We can call it get random position. 311 00:20:37,460 --> 00:20:47,000 And what we'll do is we'll just return random positions RNG next integer one two number of random positions. 312 00:20:47,300 --> 00:20:50,030 So this will return a bass part. 313 00:20:50,680 --> 00:20:53,590 And from this base part we can go ahead and get the C frame. 314 00:20:53,590 --> 00:21:00,460 So get random position, and then we get the C frame from that random position and set that on the humanoid 315 00:21:00,460 --> 00:21:02,140 root part of our handsome Squidward. 316 00:21:02,140 --> 00:21:07,150 So now our handsome Squidward will be somewhere randomly on the map, and then we can go ahead and wait 317 00:21:07,150 --> 00:21:09,820 for another random amount of time, like somewhere. 318 00:21:10,240 --> 00:21:14,320 Oh, I don't know, maybe between 1.5 and 2.1 seconds. 319 00:21:14,320 --> 00:21:17,260 So that way it stays a little bit darker for longer. 320 00:21:17,320 --> 00:21:22,570 And then again, we can just basically copy the same thing here, but turn the lights back on. 321 00:21:23,500 --> 00:21:27,100 Well, wait another random amount of time, but I want to wait a little bit. 322 00:21:27,100 --> 00:21:28,300 Uh, shorter amount of time. 323 00:21:28,570 --> 00:21:33,610 So what's going on here is that the lights turn off, and then our regular Squidward disappears. 324 00:21:33,610 --> 00:21:38,260 We wait a little bit, the lights turn back on, and then all the players see that our regular Squidward 325 00:21:38,260 --> 00:21:39,100 disappear. 326 00:21:39,100 --> 00:21:43,690 Lights turn back off again, and we put our handsome Squidward somewhere randomly on the map. 327 00:21:43,960 --> 00:21:50,620 Lights turn back on and we want the lights to turn back on for only a small amount of time. 328 00:21:50,620 --> 00:21:56,500 That way the players don't get to see our handsome Squidward for too long, so we could do Orangie next 329 00:21:56,500 --> 00:22:03,250 number anywhere between 0.1 to, I would say, a max of like 0.35 seconds, and then we would go ahead 330 00:22:03,250 --> 00:22:05,140 and turn the lights back off again. 331 00:22:06,270 --> 00:22:14,190 And then we would want to set our handsome Squidward humanoid route part C frame, equal to that default 332 00:22:14,190 --> 00:22:15,330 position dot C frame. 333 00:22:15,330 --> 00:22:16,830 So is off of the map. 334 00:22:16,980 --> 00:22:23,850 And again we're going to wait anywhere between R and G next number or next. 335 00:22:24,430 --> 00:22:25,750 Next number. 336 00:22:25,870 --> 00:22:29,110 0.5 to like 0.9 seconds. 337 00:22:30,380 --> 00:22:37,190 And then after that, we can go ahead and turn the lights back on and make sure our regular squidward's 338 00:22:37,190 --> 00:22:41,330 visibility is set to true, so we could set his visibility back to true. 339 00:22:42,420 --> 00:22:45,510 And then we could go ahead and turn the lights back on. 340 00:22:45,780 --> 00:22:50,880 And once we're done going through this if statement, then we can go ahead and wait for one second in 341 00:22:50,880 --> 00:22:51,840 this while loop. 342 00:22:51,990 --> 00:22:56,190 So that way this isn't constantly running all of the time. 343 00:22:56,400 --> 00:23:02,580 So that means about an average of every 15 seconds the lights should flicker inside of our building. 344 00:23:02,580 --> 00:23:04,590 So let's go ahead and test it out. 345 00:23:05,100 --> 00:23:11,730 So if we go and test play our game here, so far everything has loaded well on both the client and the 346 00:23:11,730 --> 00:23:12,000 server. 347 00:23:12,000 --> 00:23:15,150 But actually we did get an error in our Squidward service. 348 00:23:15,150 --> 00:23:15,900 So wrong. 349 00:23:15,900 --> 00:23:18,330 Number of arguments to insert. 350 00:23:18,510 --> 00:23:25,860 We accidentally filled out the insert function improperly, because we actually need to pass the item 351 00:23:25,860 --> 00:23:29,910 that we want to insert into idle and tracks, which is our track. 352 00:23:30,450 --> 00:23:32,460 All right, easy error we fixed. 353 00:23:32,460 --> 00:23:34,170 Let's go ahead and test that out again. 354 00:23:34,560 --> 00:23:35,640 No errors. 355 00:23:35,640 --> 00:23:37,140 Everything loaded perfectly. 356 00:23:38,430 --> 00:23:38,640 Wow. 357 00:23:38,640 --> 00:23:39,990 It actually already wanted to flicker. 358 00:23:41,130 --> 00:23:43,710 Let's actually go ahead and wait for another flicker to happen. 359 00:23:43,920 --> 00:23:45,900 So we see our regular Squidward. 360 00:23:45,900 --> 00:23:51,600 He's just chilling back there and hopefully the lights will flicker soon. 361 00:23:53,780 --> 00:23:54,170 All right. 362 00:23:54,170 --> 00:23:54,770 Lights flickered. 363 00:23:54,770 --> 00:23:55,670 He's gone. 364 00:23:56,420 --> 00:23:58,400 Oh, we see our handsome Squidward up there. 365 00:23:58,400 --> 00:24:02,270 He disappears, and our regular Squidward comes back. 366 00:24:02,330 --> 00:24:04,670 So very nice ambiance we have. 367 00:24:04,670 --> 00:24:07,280 We're able to move our camera around. 368 00:24:07,460 --> 00:24:08,660 The camera shakes a little bit. 369 00:24:08,660 --> 00:24:10,520 We've got nice music playing in the background. 370 00:24:10,520 --> 00:24:16,070 You can hear muffled rain playing and players are able to create servers here. 371 00:24:16,100 --> 00:24:19,700 Thunder in the background and all that kind of fun stuff. 372 00:24:20,510 --> 00:24:22,460 So our lobby is basically complete. 373 00:24:22,460 --> 00:24:29,240 Actually, the next thing we need to do is we need to publish our game, make sure that, uh, teleporting 374 00:24:29,270 --> 00:24:33,920 to the next place works, and go ahead and get started on the next section of our project. 375 00:24:33,920 --> 00:24:37,850 So if you're ready to start in the next section, I'll go ahead and see you in the next lecture.